﻿using System.Security.Cryptography.X509Certificates;

namespace ConsoleApp1
{
    internal class Program
    {
        //5.阅读下列代码：
        //class Promage
        //{
        //    static readonly int A = B * 10;
        //    static readonly int B = 10;
        //    public static void Main(string[] args)
        //    {
        //        Console.WriteLine(“A = { 0}; B ={ 1}”,A,B);
        //        Console.ReadLine();
        //    }
        //}
        //问题1：上述在代码在控制台中输出是“A = 0; B = 10”，请问为什么(请在代码中用注释解答)
        //问题2：请问在只修改第四行代码“static readonly int B = 10;”，使得结果变为“A = 100; B = 10”(请在vs中编写)
        private static readonly int A = B * 10;

        private static readonly int B = 10;
        //题2的正确解为将静态只读变量修改为常量private const int B = 10;
        //常量在编译时被最先处理，常量在编译时就会被赋值，且在运行时无法被修改，而静态字段在类的加载时按字段的顺序依次初始化
        //引用常量变量的变量，在编译时会被替换为实际上的常量值
        //例如

        //public int x = c;
        //public const int c = 10;
        //编译后会成为
        //public int x = 10;
        //public const int c = 10;
        

        //private const int B = 10;

        private const string str="123";

        private static void Main(string[] args)
        {
            int s = test.C;
            int z = test.z;
            Console.WriteLine(s);
            Console.WriteLine(z);
            Console.WriteLine("A = {0}; B ={1}", A, B);
            Console.ReadLine();
        }

        private class test
        {
            private int a { get; set; }
            private int b { get; set; }

            public const int C = 10;
            public static int z = x;
            public static int x = 20;
        }
    }
}